package com.qsmx.store.app.main.gift;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ListView;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.main.gift.adapter.gift.GiftPanelListLayout;
import com.qsmx.store.app.main.gift.adapter.gift.GiftTableListAdapter;
import com.qsmx.store.app.main.gift.entity.GiftEntity;
import com.qsmx.store.core.delegates.AtmosDelegate;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class GiftOrderDelegate extends AtmosDelegate {

    private GiftTableListAdapter mAdapter;

    private List<String> rowDataList = new ArrayList<>();
    private List<Integer> itemWidthList = new ArrayList<>();
    private List<GiftEntity> contentList = new ArrayList<>();

    private List<String> goodsRowDataList = new ArrayList<>();
    private List<Integer> goodsItemWidthList = new ArrayList<>();

    @BindView(R2.id.pl_root)
    GiftPanelListLayout plRoot;
    @BindView(R2.id.lv_xls)
    ListView lvXls;

    @Override
    public Object setLayout() {
        return R.layout.delegate_goods_order_search;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        initRowDataList();
        initContentDataList();
        initItemWidthList();
        initAdapter();
        plRoot.setAdapter(mAdapter);
        plRoot.getAdapter().setContentData(contentList);

    }

    private void initAdapter() {
        mAdapter = new GiftTableListAdapter(getContext(), plRoot, lvXls, R.layout.adapter_gift_list);
        mAdapter.setTitleWidth(0);
        mAdapter.setTitleHeight(40);
        mAdapter.setRowColor("#04b098");
        mAdapter.setSwipeRefreshEnabled(false);
        mAdapter.setOnRefreshListener(new CustomRefreshListener());// optional
        mAdapter.setRowDataList(rowDataList);// must have
        mAdapter.setItemWidthList(itemWidthList);// must have
        mAdapter.setItemHeight(40);// optional, dp

    }

    /**
     * 生成一份横向表头的内容
     *
     * @return List<String>
     */
    private void initRowDataList() {
        rowDataList.add(getString(R.string.order_id));
        rowDataList.add(getString(R.string.order_detail));
        rowDataList.add(getString(R.string.order_time));
        rowDataList.add(getString(R.string.order_do_person));
        rowDataList.add(getString(R.string.remark));
        rowDataList.add(getString(R.string.order_pay_status));
        rowDataList.add(getString(R.string.order_pay_type));
        rowDataList.add(getString(R.string.order_old_money));
        rowDataList.add(getString(R.string.order_true_money));
        rowDataList.add(getString(R.string.order_ic_num));
        rowDataList.add(getString(R.string.order_mem_num));
        rowDataList.add(getString(R.string.order_do));

        goodsRowDataList.add(getString(R.string.goods_name));
        goodsRowDataList.add(getString(R.string.goods_from));
        goodsRowDataList.add(getString(R.string.goods_sku));
        goodsRowDataList.add(getString(R.string.goods_type));
        goodsRowDataList.add(getString(R.string.goods_pay_money_type));
        goodsRowDataList.add(getString(R.string.goods_num));
        goodsRowDataList.add(getString(R.string.goods_cost_money));
        goodsRowDataList.add(getString(R.string.goods_sale_all_money));
        goodsRowDataList.add(getString(R.string.goods_off_money));
        goodsRowDataList.add(getString(R.string.goods_true_get_money));

    }

    private void initItemWidthList() {
        itemWidthList.add(200);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);
        itemWidthList.add(100);

        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);
        goodsItemWidthList.add(100);

    }

    private void initContentDataList() {

        contentList = new ArrayList<>();
        for (int i = 0; i <= 20; i++) {
            GiftEntity doInfo = new GiftEntity();
            contentList.add(doInfo);
        }

    }


    public class CustomRefreshListener implements SwipeRefreshLayout.OnRefreshListener {
        @Override
        public void onRefresh() {
            // don`t forget to call this
            mAdapter.getSwipeRefreshLayout().setRefreshing(false);
        }
    }
}
